package com.mzj.saas.mservice.records.controller;

import com.mzj.saas.commons.ApiData;
import com.mzj.saas.commons.ResultBean;
import com.mzj.saas.mservice.records.service.RecordsService;
import com.mzj.saas.mservice.records.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 信息备案接口
 */
@Controller
@RequestMapping("/records")
public class RecordsController {
    @Autowired
    private RecordsService recordsService;

    /**
     * 信息备案列表,实现了信息备案列表的查询
     *
     * @param accessToken 权限鉴定
     * @param status 状态，0：待确认，1：已确认
     * @param pageNumber 当前页
     * @param pageSize 页数
     * @return
     */
    @GetMapping("/recordsList")
    @ResponseBody
    public ResultBean<ApiData<RecordsListVO>> recordsList(@RequestHeader String accessToken,
                                                          @RequestParam(value = "status", required = false) Integer status,
                                                          @RequestParam(defaultValue = "0") Integer pageNumber,
                                                          @RequestParam(defaultValue = "5") Integer pageSize) {
        return recordsService.recordsList(accessToken, status, pageNumber, pageSize);
    }

    /**
     * 责任书内容
     *
     * @param communityId
     * @return
     */
    @GetMapping("/liabilityContent")
    @ResponseBody
    public ResultBean<Map<String, Object>> liabilityContent(@RequestParam(value = "communityId") Long communityId) {
        return recordsService.liabilityContent(communityId);
    }

    /**
     * 上传签字图片，实现签字图片的上传
     *
     * @param houseId 公租房id
     * @param file 签字图片
     * @return
     */
    @PostMapping("/uploadSign")
    @ResponseBody
    public ResultBean<Object> uploadSign(@RequestParam(value = "houseId") String houseId,
                                         @RequestParam(value = "file") MultipartFile file) {
        return recordsService.uploadSign(houseId, file);
    }

    /**
     * 提交信息备案
     *
     * @param accessToken 权限鉴定
     * @param liabilityNumber 责任书序号
     * @param houseId 公租房id
     * @param matchUserId 承租人id
     * @param applyId 申请id
     * @param signatureFile 签字文件url
     * @return
     */
    @GetMapping("/submitRecords")
    @ResponseBody
    public ResultBean<Object> submitRecords(@RequestHeader String accessToken,
                                            @RequestParam(value = "liabilityNumber", required = false) String liabilityNumber,
                                            @RequestParam(value = "houseId") String houseId,
                                            @RequestParam(value = "matchUserId") String matchUserId,
                                            @RequestParam(value = "applyId") Long applyId,
                                            @RequestParam(value = "signatureFile") String signatureFile,
                                            @RequestParam(value = "orgId") Long orgId) {
        return recordsService.submitRecords(accessToken, liabilityNumber, houseId, matchUserId, applyId, signatureFile, orgId);
    }

    /**
     * 确认信息备案
     *
     * @param accessToken 权限鉴定
     * @param recordsId 信息备案id
     * @return
     */
    @GetMapping("/confirmRecords")
    @ResponseBody
    public ResultBean<Object> confirmRecords(@RequestHeader String accessToken,
                                             @RequestParam(value = "recordsId") Long recordsId) {
        return recordsService.confirmRecords(accessToken, recordsId);
    }

    /**
     * 批量确认信息备案
     *
     * @param accessToken
     * @param recordsIds
     * @return
     */
    @GetMapping("/batchConfirmRecords")
    @ResponseBody
    public ResultBean<Object> batchConfirmRecords(@RequestHeader String accessToken,
                                                  @RequestParam(value = "recordsIds") List<Long> recordsIds) {
        return recordsService.batchConfirmRecords(accessToken, recordsIds);
    }

    /**
     * 责任书列表，实现责任书列表的展示
     *
     * @param accessToken 权限鉴定
     * @param liabilityNumber 责任书序号
     * @param name 名称
     * @param communityId 社区Id
     * @param pageNumber 当前页
     * @param pageSize 页数
     * @return
     */
    @GetMapping("/liabilityList")
    @ResponseBody
    public ResultBean<ApiData<LiabilityListVO>> liabilityList(@RequestHeader String accessToken,
                                                              @RequestParam(value = "liabilityNumber", required = false) String liabilityNumber,
                                                              @RequestParam(value = "name", required = false) String name,
                                                              @RequestParam(value = "communityId", required = false) Long communityId,
                                                              @RequestParam(defaultValue = "0") Integer pageNumber,
                                                              @RequestParam(defaultValue = "5") Integer pageSize) {
        return recordsService.liabilityList(accessToken, liabilityNumber, name, communityId, pageNumber, pageSize);
    }

    /**
     * 激活或禁用责任书
     *
     * @param accessToken 权限鉴定
     * @param liabilityNumber 责任书序号
     * @return
     */
    @GetMapping("/updateEnableStatus")
    @ResponseBody
    public ResultBean<Object> updateEnableStatus(@RequestHeader String accessToken,
                                                 @RequestParam(value = "liabilityNumber") String liabilityNumber) {
        return recordsService.updateEnableStatus(accessToken, liabilityNumber);
    }

    /**
     * 删除责任书
     *
     * @param accessToken 权限鉴定
     * @param liabilityNumber 责任书序号
     * @return
     */
    @GetMapping("/deleteLiability")
    @ResponseBody
    public ResultBean<Object> deleteLiability(@RequestHeader String accessToken,
                                              @RequestParam(value = "liabilityNumber") String liabilityNumber) {
        return recordsService.deleteLiability(accessToken, liabilityNumber);
    }

    /**
     * 责任书模板下载
     *
     * @param accessToken
     */
    @GetMapping("/wordDownload")
    public void wordDownLoad(@RequestHeader String accessToken) {
        this.recordsService.wordDownload(accessToken);
    }

    /**
     * 查询社区，实现社区的查询
     *
     * @param accessToken 权限鉴定
     * @return
     */
    @GetMapping("/findCommunity")
    @ResponseBody
    public ResultBean<List<CommunityVO>> findCommunity(@RequestHeader String accessToken) {
        return recordsService.findCommunity(accessToken);
    }

    /**
     * 上传责任书模板
     *
     * @param accessToken 权限鉴定
     * @param communityId 社区id
     * @param file 文件
     * @return
     */
    @PostMapping("/wordImport")
    @ResponseBody
    public ResultBean<Object> wordImport(@RequestHeader String accessToken,
                                         @RequestParam(value = "communityId") Long communityId,
                                         @RequestParam("file") MultipartFile file) {
        return recordsService.wordImport(accessToken, communityId, file);
    }

    /**
     * 查看责任书
     *
     * @param accessToken
     * @param liabilityNumber
     * @return
     */
    @GetMapping("/findLiability")
    @ResponseBody
    public ResultBean<String> findLiability(@RequestHeader String accessToken,
                                            @RequestParam(value = "liabilityNumber") String liabilityNumber) {
        return recordsService.findLiability(accessToken, liabilityNumber);
    }

    /**
     * 备案变更查询同住人
     *
     * @param vo
     * @return
     */
    @PostMapping("/findRecordCohabit")
    @ResponseBody
    public ResultBean<RecordCohabitVO> findRecordCohabit(@RequestBody CohabitParam vo) {
        return recordsService.findRecordCohabit(vo);
    }

    /**
     * 保存备案临时同住人
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("/saveRecordCohabit")
    @ResponseBody
    public ResultBean<String> saveRecordCohabit(@RequestHeader String accessToken,
                                                @RequestBody RecordCohabitVO vo) {
        return recordsService.saveRecordCohabit(accessToken, vo);
    }

    /**
     * 保存备案变更
     *
     * @param accessToken
     * @param vo
     * @return
     */
    @PostMapping("/saveRecordsChange")
    @ResponseBody
    public ResultBean<Object> saveRecordsChange(@RequestHeader String accessToken,
                                                @RequestBody RecordsChangeVO vo) {
        return recordsService.saveRecordsChange(accessToken, vo);
    }

}
